{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "0c08c008",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[50, 26, 44],\n",
       "       [69, 10,  0],\n",
       "       [56, 83, 99],\n",
       "       [ 2, 93, 97],\n",
       "       [85, 81, 59],\n",
       "       [96, 19, 62],\n",
       "       [14, 89, 26],\n",
       "       [89, 33, 84],\n",
       "       [39, 36, 82],\n",
       "       [63, 92, 40],\n",
       "       [85, 82, 89],\n",
       "       [30, 66, 37],\n",
       "       [ 7, 27, 38],\n",
       "       [53, 65, 39],\n",
       "       [75, 77, 63],\n",
       "       [37, 57, 84],\n",
       "       [77, 44, 12],\n",
       "       [10, 89, 85],\n",
       "       [54, 28,  3],\n",
       "       [33,  5, 76],\n",
       "       [56, 27, 37],\n",
       "       [25, 44, 43],\n",
       "       [24,  0, 90],\n",
       "       [17, 59, 58],\n",
       "       [81, 63, 13],\n",
       "       [78, 26, 95],\n",
       "       [98, 44, 40],\n",
       "       [51, 58,  6],\n",
       "       [94, 80, 82],\n",
       "       [37, 16, 92],\n",
       "       [56, 32, 52],\n",
       "       [28, 23, 65],\n",
       "       [23, 84, 17],\n",
       "       [83, 33, 17],\n",
       "       [25, 55,  8],\n",
       "       [91, 36, 52],\n",
       "       [ 1, 89, 58],\n",
       "       [86, 67, 21],\n",
       "       [80, 41, 16],\n",
       "       [35, 91, 42],\n",
       "       [38,  8, 78],\n",
       "       [ 6, 48, 22],\n",
       "       [ 8, 37,  7],\n",
       "       [42, 82, 36],\n",
       "       [65, 75, 27],\n",
       "       [69, 65, 94],\n",
       "       [64,  8, 53],\n",
       "       [46, 86, 69],\n",
       "       [89, 49, 41],\n",
       "       [64, 21, 18]], dtype=uint8)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[70, 42, 62],\n",
       "       [29, 80, 64],\n",
       "       [65, 33,  5],\n",
       "       [49, 64, 40],\n",
       "       [ 0, 15, 84],\n",
       "       [71, 76, 85],\n",
       "       [85, 83, 10],\n",
       "       [62,  9, 10],\n",
       "       [ 1, 79, 86],\n",
       "       [16, 98,  7],\n",
       "       [51, 93,  1],\n",
       "       [99, 54,  0],\n",
       "       [91, 60, 99],\n",
       "       [ 8, 95, 77],\n",
       "       [81, 15, 41],\n",
       "       [13, 19, 36],\n",
       "       [51, 74, 36],\n",
       "       [50, 39,  1],\n",
       "       [ 2, 50, 71],\n",
       "       [26, 35,  8],\n",
       "       [89,  0, 94],\n",
       "       [52, 17, 67],\n",
       "       [ 2, 44, 53],\n",
       "       [77, 21, 89],\n",
       "       [68, 76, 76],\n",
       "       [44, 72, 47],\n",
       "       [48, 70,  1],\n",
       "       [88, 44, 59],\n",
       "       [68, 11, 98],\n",
       "       [34, 43, 89],\n",
       "       [75, 73, 11],\n",
       "       [58, 93, 40],\n",
       "       [33, 96, 11],\n",
       "       [61, 84,  7],\n",
       "       [20, 82, 13],\n",
       "       [21, 19, 95],\n",
       "       [74, 45, 50],\n",
       "       [21, 95, 46],\n",
       "       [ 7, 52,  7],\n",
       "       [82, 43, 31],\n",
       "       [83, 14, 41],\n",
       "       [96, 13, 91],\n",
       "       [29,  0, 12],\n",
       "       [14, 58, 76],\n",
       "       [29, 16, 55],\n",
       "       [72, 62, 24],\n",
       "       [77, 58,  0],\n",
       "       [91, 32, 93],\n",
       "       [97, 76, 35],\n",
       "       [36, 42, 52]], dtype=uint8)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[51, 21, 49],\n",
       "       [ 0, 33, 98],\n",
       "       [93, 14, 11],\n",
       "       [43, 75, 57],\n",
       "       [53, 25, 43],\n",
       "       [36, 73, 94],\n",
       "       [96, 84, 64],\n",
       "       [63, 42, 82],\n",
       "       [64, 76, 17],\n",
       "       [44, 48, 89],\n",
       "       [24, 43, 15],\n",
       "       [58,  9, 76],\n",
       "       [ 4, 22, 51],\n",
       "       [42, 17, 67],\n",
       "       [80, 70, 57],\n",
       "       [ 3, 48, 90],\n",
       "       [90, 22, 54],\n",
       "       [22, 50, 12],\n",
       "       [47, 20, 82],\n",
       "       [72, 11, 76],\n",
       "       [ 1, 94, 17],\n",
       "       [93,  9, 14],\n",
       "       [47, 46, 69],\n",
       "       [73, 83, 89],\n",
       "       [39, 73,  4],\n",
       "       [52, 61, 89],\n",
       "       [31, 10, 92],\n",
       "       [84, 59, 24],\n",
       "       [27, 57, 45],\n",
       "       [42, 82, 61],\n",
       "       [62, 67, 63],\n",
       "       [37, 53, 64],\n",
       "       [ 3, 33, 68],\n",
       "       [21, 63, 53],\n",
       "       [28, 79, 76],\n",
       "       [40, 82, 65],\n",
       "       [86, 18, 15],\n",
       "       [38, 65,  4],\n",
       "       [39, 17, 77],\n",
       "       [10, 42, 82],\n",
       "       [91, 23, 56],\n",
       "       [33, 39, 52],\n",
       "       [64, 12, 14],\n",
       "       [14, 95, 39],\n",
       "       [30, 48, 68],\n",
       "       [89, 67, 45],\n",
       "       [13, 16, 61],\n",
       "       [17, 92, 49],\n",
       "       [43, 90, 68],\n",
       "       [63, 22,  5]], dtype=uint8)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[59, 75, 10],\n",
       "       [98, 56, 84],\n",
       "       [59, 11, 32],\n",
       "       [37, 83, 98],\n",
       "       [21, 76, 50],\n",
       "       [97, 39, 47],\n",
       "       [ 2, 49, 17],\n",
       "       [ 6, 15, 16],\n",
       "       [99, 14, 46],\n",
       "       [22,  8, 23],\n",
       "       [77, 15, 12],\n",
       "       [73, 90,  4],\n",
       "       [ 3, 69,  3],\n",
       "       [44, 93,  2],\n",
       "       [61, 71, 21],\n",
       "       [ 4, 68, 70],\n",
       "       [71, 66, 21],\n",
       "       [97, 41, 28],\n",
       "       [22, 93, 14],\n",
       "       [47, 84, 28],\n",
       "       [18, 68,  6],\n",
       "       [65, 38, 13],\n",
       "       [28, 30, 37],\n",
       "       [65, 16, 39],\n",
       "       [17, 45, 68],\n",
       "       [66, 38, 43],\n",
       "       [59, 68, 70],\n",
       "       [51,  0, 37],\n",
       "       [29, 91, 73],\n",
       "       [26, 46, 93],\n",
       "       [94, 34, 85],\n",
       "       [84, 96, 73],\n",
       "       [50, 34, 56],\n",
       "       [40, 36, 35],\n",
       "       [90, 42,  6],\n",
       "       [62, 89, 54],\n",
       "       [33, 13, 77],\n",
       "       [49, 67, 61],\n",
       "       [49,  4, 14],\n",
       "       [ 5, 59, 88],\n",
       "       [15, 73, 67],\n",
       "       [15,  6, 59],\n",
       "       [ 2, 40, 82],\n",
       "       [97, 45, 14],\n",
       "       [22, 98, 57],\n",
       "       [44, 25, 52],\n",
       "       [49, 12, 97],\n",
       "       [86, 58, 68],\n",
       "       [34, 12, 31],\n",
       "       [34, 66, 27]], dtype=uint8)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[54, 80, 28],\n",
       "       [71, 62, 92],\n",
       "       [49, 96, 47],\n",
       "       [90, 42, 35],\n",
       "       [81, 23, 69],\n",
       "       [63, 98, 53],\n",
       "       [78, 36, 47],\n",
       "       [78, 24, 50],\n",
       "       [36, 80,  6],\n",
       "       [65, 97,  2],\n",
       "       [81,  2, 89],\n",
       "       [73,  7, 10],\n",
       "       [36, 77, 13],\n",
       "       [62,  4, 14],\n",
       "       [87, 72, 21],\n",
       "       [22, 93, 64],\n",
       "       [56, 97, 87],\n",
       "       [45,  3, 26],\n",
       "       [19, 76,  7],\n",
       "       [85, 55, 24],\n",
       "       [46, 38, 80],\n",
       "       [54, 30, 45],\n",
       "       [51, 90, 40],\n",
       "       [69,  7, 59],\n",
       "       [ 1, 43, 36],\n",
       "       [70, 58, 11],\n",
       "       [74,  6, 40],\n",
       "       [26, 76, 12],\n",
       "       [39, 31, 11],\n",
       "       [64, 60, 83],\n",
       "       [64, 36, 19],\n",
       "       [37, 79, 37],\n",
       "       [62, 65, 57],\n",
       "       [30, 21, 54],\n",
       "       [85,  5, 71],\n",
       "       [54, 35, 25],\n",
       "       [11, 86, 98],\n",
       "       [83, 76, 75],\n",
       "       [76, 87, 78],\n",
       "       [60, 64, 89],\n",
       "       [44, 42,  7],\n",
       "       [19, 75, 97],\n",
       "       [87, 61, 78],\n",
       "       [74, 62, 19],\n",
       "       [16, 88, 71],\n",
       "       [33, 67, 43],\n",
       "       [ 9, 99,  5],\n",
       "       [67, 61, 59],\n",
       "       [ 2,  0, 21],\n",
       "       [57,  4, 92]], dtype=uint8)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[85, 11, 35],\n",
       "       [36,  5, 79],\n",
       "       [18, 66, 83],\n",
       "       [45, 66, 33],\n",
       "       [95, 33, 11],\n",
       "       [12, 12, 10],\n",
       "       [80, 61, 59],\n",
       "       [ 9, 27, 37],\n",
       "       [18, 93,  7],\n",
       "       [30, 88, 53],\n",
       "       [96, 30, 38],\n",
       "       [90, 76, 48],\n",
       "       [48,  8, 66],\n",
       "       [32, 50, 37],\n",
       "       [ 0, 98, 43],\n",
       "       [90, 99, 13],\n",
       "       [19, 92, 68],\n",
       "       [72, 73, 45],\n",
       "       [15, 36,  3],\n",
       "       [ 9, 21, 35],\n",
       "       [16, 92, 29],\n",
       "       [29, 99, 55],\n",
       "       [ 0, 17, 23],\n",
       "       [ 5, 35, 22],\n",
       "       [ 6, 91, 52],\n",
       "       [90, 79, 14],\n",
       "       [67, 53, 34],\n",
       "       [32, 93, 71],\n",
       "       [44, 90,  4],\n",
       "       [74, 42, 42],\n",
       "       [58, 77,  1],\n",
       "       [73, 28, 27],\n",
       "       [73, 32, 64],\n",
       "       [43,  6, 91],\n",
       "       [93, 62, 38],\n",
       "       [18, 60, 48],\n",
       "       [81, 98, 26],\n",
       "       [89,  2, 94],\n",
       "       [60, 74, 10],\n",
       "       [17, 93, 26],\n",
       "       [85, 51, 87],\n",
       "       [27, 14, 55],\n",
       "       [48, 91, 60],\n",
       "       [30, 24, 17],\n",
       "       [62, 15, 35],\n",
       "       [56, 56, 93],\n",
       "       [15,  3, 51],\n",
       "       [25, 23, 12],\n",
       "       [33, 79,  7],\n",
       "       [94, 54, 25]], dtype=uint8)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "##1.\t随机数生成六个班的考试成绩，3门考试：Python、数学、语文。每个班50人 \n",
    "class1=np.random.randint(0,100,size=(50,3),dtype = 'uint8')\n",
    "class2=np.random.randint(0,100,size=(50,3),dtype = 'uint8')\n",
    "class3=np.random.randint(0,100,size=(50,3),dtype = 'uint8')\n",
    "class4=np.random.randint(0,100,size=(50,3),dtype = 'uint8')\n",
    "class5=np.random.randint(0,100,size=(50,3),dtype = 'uint8')\n",
    "class6=np.random.randint(0,100,size=(50,3),dtype = 'uint8')\n",
    "display(class1,class2,class3,class4,class5,class6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "27810a1d",
   "metadata": {},
   "outputs": [],
   "source": [
    "##2.将六个班的考试成绩进行合并得到score\n",
    "score=np.concatenate([class1,class2,class3,class4,class5,class6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "id": "e127b699",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int32')"
      ]
     },
     "execution_count": 169,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##3.\t生成性别数组sex，水平叠加数组sex和score得到data\n",
    "#step1随机生成一个item为字符类型的数组——sex\n",
    "sex_num=np.random.randint(0,2,size=(300,1))\n",
    "#将随机数字改为字符 0为m 1为f\n",
    "sex=np.empty((300,1),dtype=str)\n",
    "cond=sex_num==0\n",
    "sex[cond]='m'\n",
    "cond2=sex==''\n",
    "sex[cond2]='f'\n",
    "#step2 叠加数组sex和score\n",
    "data=np.concatenate([sex,score],axis=1)\n",
    "data1=np.concatenate([sex_num,score],axis=1)#用于后面计算\n",
    "data1.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "id": "c498203c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 0, 0])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0, 99, 99, 99])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0.        , 50.75324675, 50.98051948, 44.83766234])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0., 49., 49., 45.])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0.        , 27.53069401, 29.90102087, 28.48181712])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "##4.分别计算男女生各科成绩统计指标：最小值、最大值、平均分、中位数、标准差\n",
    "cond3= data1[:,0] == 0 #女生\n",
    "score_min = data1[cond3].min(axis = 0)\n",
    "score_max = data1[cond3].max(axis=0)\n",
    "score_mean = data1[cond3].mean(axis=0)\n",
    "score_median = np.median(data1[cond3],axis=0)\n",
    "score_std = data1[cond3].std(axis = 0)\n",
    "display(score_min,score_max,score_mean,score_median,score_std)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "id": "807e5de1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 0, 0, 1])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 1, 98, 98, 99])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 1.        , 48.23972603, 51.23972603, 48.5       ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 1. , 50.5, 54. , 47.5])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0.        , 29.55614689, 28.64791101, 29.69669739])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cond4= data1[:,0] == 1 #男生\n",
    "score_min = data1[cond4].min(axis = 0)\n",
    "score_max = data1[cond4].max(axis=0)\n",
    "score_mean = data1[cond4].mean(axis=0)\n",
    "score_median = np.median(data1[cond4],axis=0)\n",
    "score_std = data1[cond4].std(axis = 0)\n",
    "display(score_min,score_max,score_mean,score_median,score_std)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
